@extends('layouts.default') @section('main')
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb">
                <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i
                            class="icon-home"></i> 首页</a>
                <a href="{{url('news/list')}}" class="tip-bottom">资讯管理</a>
                <a href="{{url('news/photos?id='.$article_id)}}" class="tip-bottom">图片管理</a>
                <a href="#" class="current">新增图片</a>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span9">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-align-justify"></i>
						</span>
                            <h5>新增图片</h5>
                        </div>
                        <div class="widget-content nopadding">
                            <form action="{{url('news/add-photo')}}" method="post" id="adForm" class="form-horizontal">
                                <div class="control-group">
                                    <label class="control-label">资讯图片 :</label>
                                    <div class="controls">
                                        <input type="hidden" class="span11" name="articlephoto"
                                               placeholder="新增一个图片"  />
                                        <img src="" width="120px" name="articlephoto" height="120px"/>
                                        <a href="javascript:void(0);" id="uploadWxphotoBtn"  onclick="javascript:openBrowse('uploadWxphotoBtn','uploadWxphoto');">点击上传</a>
                                        <input type="file" id="uploadWxphoto" style="display:none" name="myfile" size="10" onchange="fileUpload('uploadWxphoto','articlephoto')"/>
                                    </div>
                                </div>

                                <div class="control-group" id="add">
                                    <label class="control-label"></label>
                                    <div class="controls">
                                        <button type="button" id="addphoto" class="btn btn-success">继续新增图片</button>
                                    </div>
                                </div>

                                <input type="hidden" class="span11" name="formType" value="create" />
                                <div class="form-actions">
                                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                    <input type="hidden" name="article_id" value="{{$article_id}}">
                                    <button type="button" id="doSave" class="btn btn-success">保存</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        var n = 1;
        $("#addphoto").click(function(){
            n++;
            var html = '';
            html +='<div class="control-group">';
            html +='<label class="control-label">资讯图片 :</label>';
            html +='<div class="controls">';
            html +='<input type="hidden" class="span11" name="articlephoto'+n+'" placeholder="新增一个图片" />';
            html +='<img src="" width="120px" name="articlephoto'+n+'" height="120px"/>';
            html +='<a href="javascript:void(0);" id="uploadPhotoBtn"  onclick="javascript:openBrowse(\'upload'+n+'PhotoBtn\',\'uploadPhoto'+n+'\');">点击上传</a>';
            html +='<input type="file" id="uploadPhoto'+n+'" style="display:none" name="myfile" size="10" onchange="fileUpload(\'uploadPhoto'+n+'\',\'articlephoto'+n+'\')"/>';
            html +='</div>';
            html +='</div>';
            $("#add").before(html);
        });

        $("#doSave").click(function(){
            $(this).attr('disabled','disabled');

            ajaxRequest($('#adForm').serializeArray(),$('#adForm').attr('action'),function(data){
                if(data.status){
                    alert(data.message);
                    window.location.href = data.forwardUrl;
                }else{
                    $("#doSave").removeAttr('disabled');

                    alert(data.message);
                }
            });
        });
    </script>

    <script type="text/javascript" src="{{URL::asset('js/')}}/ajaxfileupload.js"></script>
    <script type="text/javascript" src="{{URL::asset('js/')}}/common.js"></script>
@stop
